// @ts-ignore
/* eslint-disable */
import {request} from 'umi';
import {AccountListItem} from './data';

/** 获取规则列表 GET /api/rule */
export async function account(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  sorter: any,
  options?: { [key: string]: any },
) {
  return request<{
    data: AccountListItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/v2/enterprise/account/list', {
    method: 'GET',
    params: {
      ...params,
      orderByColumn: Object.keys(sorter)[0],
      isAsc: Object.values(sorter)[0],
    },
    ...(options || {}),
  });
}

export async function loadAccount(param: { accountId?: number }): Promise<{ data: AccountListItem }> {
  console.log(param)
  return request(`/v2/enterprise/account/${param.accountId}`, {method: "GET"});
}

export async function updateAccount(data: { [key: string]: any }, options?: { [key: string]: any }) {
  return request<AccountListItem>('/v2/enterprise/account', {
    data,
    method: 'PUT',
    ...(options || {}),
  });
}

export async function addAccount(data: { [key: string]: any }, options?: { [key: string]: any }) {
  return request<AccountListItem>('/v2/enterprise/account', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

export async function removeAccount(data: number[], options?: { [key: string]: any }) {
  debugger;
  return request<Record<string, any>>('/v2/enterprise/account', {
    data,
    method: 'DELETE',
    ...(options || {}),
  });
}
